﻿@model DDDSample.UI.Mvc.Models.AssignToRouteViewModel
@{
    ViewBag.Title = "Change destination of cargo";
}
<h2>
    Select route for cargo @Model.Cargo.Id</h2>
<p>
    Cargo is going from
    @Model.Cargo.Origin
    to
    @Model.Cargo.Destination .
</p>
<div>
    @{var i = 1;}
    @foreach (var routeCandidate in Model.RouteCandidates)
    {
        using (Html.BeginForm())
        {
            <table>
            <caption>Route candidate @i</caption>
            <thead>
                <tr>
                    <td>
                        Voyage
                    </td>
                    <td>
                        From
                    </td>
                    <td>
                    </td>
                    <td>
                        To
                    </td>
                    <td>
                    </td>
                </tr>
            </thead>
            <tbody>
                @{ var legIndex = 0; }
                @foreach (var leg in routeCandidate.Legs)
                {
                    @Html.Hidden("Legs["+legIndex+"].VoyageNumber", leg.VoyageNumber) 
                    @Html.Hidden("Legs["+legIndex+"].From", leg.From) 
                    @Html.Hidden("Legs["+legIndex+"].LoadTime", leg.LoadTime) 
                    @Html.Hidden("Legs["+legIndex+"].To", leg.To) 
                    @Html.Hidden("Legs["+legIndex+"].UnloadTime", leg.UnloadTime)                     
                    legIndex++;
                    <tr>
                        <td>
                            @leg.VoyageNumber
                        </td>
                        <td>
                            @leg.From
                        </td>
                        <td>
                            @leg.LoadTime
                        </td>
                        <td>
                            @leg.To
                        </td>
                        <td>
                            @leg.UnloadTime
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        <input type="submit" value="Assign cargo to this route" />
        }
        i++;
    }
</div>
